package com.example.flow.pipeline.core;

import com.example.flow.pipeline.model.result.FlowResult;
import lombok.extern.slf4j.Slf4j;

/**
 * @Desprication: DefaultValve
 * @Author: YangBin
 * @Date: created in 23:58 2020/2/23
 * @Modify By:
 */
@Slf4j
final class DefaultValve extends AbstractValve {

    private final FlowHandler handler;

    protected DefaultValve(String name, DefaultPipeline pipeline, FlowHandler handler) {
        super(name, pipeline);
        this.handler = handler;
    }

    @Override
    public FlowResult<?> execute() {
        FlowResult<?> res = handler.handle();
        return processContinue(res);
    }

    protected FlowResult<?> processContinue(FlowResult<?> res) {
        if (PipeLine.tailValveName.equals(next.name())) {
            log.info("PipeLine Completed.");
            return res;
        }
        return next.execute();
    }

}
